package beautysalonsystem.mapper;

import beautysalonsystem.dto.OrderDTO;
import beautysalonsystem.pojo.Order;
import org.apache.ibatis.annotations.*;

import java.sql.Date;
import java.time.LocalDate;
import java.util.List;

@Mapper
public interface OrderMapper {

    //查询某一天的order信息
    @Select("select o.id id, c.username customer, a.username admin, \n" +
            "o.date as date, o.cell cell, o.status status, o.log log \n" +
            "from order_tb o inner join admin_tb a on  \n" +
            "o.admin = a.id inner join customer_tb c on \n" +
            "o.customer = c.id \n" +
            "where o.date = #{date}")
    List<OrderDTO> getOrderByDate(LocalDate date);

    //根据id查询order信息
    @Select("select * from order_tb t where t.id = #{id}")
    Order getOrderById(Integer id);

    //在某一天上新增order信息
    @Insert("insert into order_tb values (null, #{customer}, #{admin}, #{date}, #{cell}, 1, null)")
    void addOrder(Order order);

    //修改order信息
    @Update("update order_tb t set t.status = #{status}, t.log = #{log}")
    void updateOrder(Order order);

    //删除某个order信息
    @Delete("delete from order_tb where id = #{id}")
    void deleteOrder(Integer id);

    //根据date和cell查询order
    @Select("select * from order_tb t where t.date = #{date} and t.cell = #{cell}")
    Order getOrderByDateAndCell(@Param("date") Date date, @Param("cell") Integer cell);

    //更改订单状态
    @Update("update order_tb t set t.status = #{status}")
    void updateOrderState(int status);
}
